package com.czy.workflow.demo;

import cn.hutool.http.HttpUtil;
import com.czy.workflow.core.annotation.TaskExecutor;
import com.czy.workflow.core.annotation.TaskExecutorMethod;
import com.czy.workflow.core.context.FlowContext;
import com.czy.workflow.core.exception.FlowException;
import com.czy.workflow.core.model.TaskInfo;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.logging.Logger;

/**
 * Created by admin on 2019/8/31.
 */


@TaskExecutor(flowCode = "F2")
public class WorkDemo2 {

    Logger logger = Logger.getLogger(WorkDemo2.class.getName());

    @Autowired
    FlowContext flowContext;

    @TaskExecutorMethod(nodeCode = "N1")
    public boolean handleNote1(TaskInfo taskInfo){
        logger.info("----F2---N1----");
        return true;
    }

    @TaskExecutorMethod(nodeCode = "N2")
    public boolean handleNote2(TaskInfo taskInfo){
        logger.info("----F2---N2----");
        return true;
    }

    public void startDemo(){
        TaskInfo taskInfo = new TaskInfo();
        taskInfo.setDocId("1");
        taskInfo.setFlowId("2");
        try {
            flowContext.getTaskExecutor().startTask(taskInfo);
        } catch (FlowException e) {
            e.printStackTrace();
        }
        String host = "http://localhost:8090";
        logger.info(HttpUtil.post(host + "/workflow/submit/1/2?option=Y", ""));

        logger.info(HttpUtil.post(host + "/workflow/submit/1/3?option=N", ""));

        logger.info(HttpUtil.post(host + "/workflow/submit/1/2?option=Y", ""));

        logger.info(HttpUtil.post(host + "/workflow/submit/1/3?option=Y", ""));
    }


}
